#!/usr/bin/env python3
"""
图片识别与对比工具入口文件
"""
import sys
import os
import asyncio
import qasync  # 用于Qt与asyncio集成

# 添加项目根目录到路径
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from PySide6.QtWidgets import QApplication
from src.models.recognition_model import RecognitionModel
from src.views.main_window import MainWindowView
from src.controllers.recognition_controller import RecognitionController
from src.utils.style_manager import StyleManager
from config.settings import UI

def main():
    """应用程序入口"""
    # 创建QApplication实例
    app = QApplication(sys.argv)
    
    # 加载和应用全局样式
    style_file = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), UI["style_file"])
    StyleManager.apply_global_style(app, style_file)
    
    # 创建MVC组件
    model = RecognitionModel()
    view = MainWindowView()
    controller = RecognitionController(model, view)
    
    # 显示主窗口
    view.show()
    
    # 设置asyncio事件循环
    loop = qasync.QEventLoop(app)
    asyncio.set_event_loop(loop)
    
    # 运行事件循环
    with loop:
        loop.run_forever()
    
    # 清理
    sys.exit(0)

if __name__ == "__main__":
    main() 